<template>
    <div>
        <div class="item" v-for="(item,index) in this.$store.state.cartitems" :key="index">
            <p class="title">{{item.name}}</p>
            <p class="price">￥{{item.price}}</p>
            <p>
                <button @click="minus(item.id)">-</button>
                {{item.count}}
                <button @click="plus(item.id)">+</button>
            </p>
            <p class="del" @click="del(item.id)">x</p>
        </div>
        <div class="bottom">
            总计:￥{{this.$store.getters.total}}
        </div>
    </div>
</template>
<style>
.botton{
    margin: 10px;
    font-size: 18px;
    font-weight: bold;
}
.item {
    margin: 10px;
    background-color:#eee;
    border: 1px solid #ddd;
    height: 80px;
    padding: 10px;
    position: relative;
}
.del{
    position: absolute;
    top:0;right: 0;
}
.item .title{
    font-weight: bold;
    font-size: 18px;
}
.item .price{
    color: crimson;
    margin: 10px 0px;
}
.item button{
    display: inline-block;
    width: 25px;
    height: 25px;
    text-align: center;
    line-height: 25px;
    border: 1px solid #aaa;
    background-color: black;
    color: white;
    padding: 0px;
}

</style>
<script>
export default {
    methods:{
        minus(id){
           this.$store.commit('minus',id)
        },
        plus(id){
            this.$store.commit('plus',id)
        },
        del(id){
            // 获取当前选中购物项的id
            console.log(id);
            this.$store.dispatch('del',id)
        }
    }
}
</script>


